﻿using Prism.Commands;
using Prism.Mvvm;
using Prism.Regions;
using Prism.Services.Dialogs;
using System.Windows;
using CommunityToolkit.Mvvm.ComponentModel; // [ObservableProperty]
using CommunityToolkit.Mvvm.Input;            // [RelayCommand]

namespace BlankApp1.ViewModels
{
    public partial class MainWindowViewModel : ObservableObject
    {
        private readonly IDialogService _dialogService;

        private readonly IRegionManager _regionManager;
        

        [ObservableProperty]
        public string title = "Prism Application";
        

        public MainWindowViewModel()
        {

        }

        public MainWindowViewModel(IRegionManager regionManager, IDialogService dialogService)
        {
            _regionManager = regionManager;
            Title = "wpf+prism应用";

            // 注册视图，默认显示，这里使用UserControl1
            // 使用Page1报错，window1也报错
            _regionManager.RegisterViewWithRegion("ContentRegion", typeof(Views.UserControl1));
            _regionManager.RegisterViewWithRegion("West_ContentRegion", typeof(Views.UserControl2));

            _dialogService = dialogService;
        }


        [RelayCommand]
        private void ShowDialog()
        {
            // 显示对话框
            _dialogService.ShowDialog("MyDialogView", new DialogParameters(), r =>
            {
                if (r.Result == ButtonResult.OK)
                {
                    // 处理 OK 结果
                    MessageBox.Show("已点击确定按钮");
                }
                else if (r.Result == ButtonResult.Cancel)
                {
                    // 处理 Cancel 结果
                    MessageBox.Show("已点击取消按钮");
                }
            });


            // 导航发生变化
            _regionManager.Regions["ContentRegion"].RequestNavigate("MyDialogView");
            

        }
    }
}
